package com.test0109;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

public class Test03 {
    public static void main(String[] args) throws ParseException {
        Date date = new Date();  //getTime 获取从1970-01-01 开始的毫秒数
        date.setTime(date.getTime()+(1000L*60*60*24*100));//1000*60*24*100 100天的毫秒数
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println(format);

        Date a = new Date();
        String b = "2025年01月29日";
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy年MM月dd日");
        Date c = simpleDateFormat1.parse(b);//将字符串转成Date类型
        long day = ((c.getTime()-a.getTime())/1000/60/60/24);
        System.out.println(day+"天");



        // (3)计算100天之后的日期、计算今天距离过年还差多少天
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        String newDate = simpleDateFormat.format(date);
//        System.out.println("当前日期："+newDate);
//
//        Calendar instance = Calendar.getInstance();
//        instance.setTime(date);
//        instance.add(Calendar.DAY_OF_YEAR,100);
//        Date time = instance.getTime();
//
//        String format = simpleDateFormat.format(time);
//        System.out.println("100天后日期:"+format);
//
//
        LocalDate now = LocalDate.now();//当前时间
        LocalDate localDate = now.withDayOfMonth(29).withMonth(1);//春节

        if(now.getMonthValue()>1||now.getMonthValue()==1 && now.getDayOfMonth()>29){
            localDate = localDate.plusYears(1);
        }
        long between = ChronoUnit.DAYS.between(now, localDate);

        System.out.println("距离新年："+between+"天");


    }
}
